
class JQCategoryCreateService extends global.JQService {
    async do_action(){
		
		if(!this.conn)console.log('do_action::conn error');
		let data_obj = this.req_obj.data_obj;
		let inst = global.JQTableIF.instance('menu_table',this.conn);
		
		// _addParams
		
		
		if(!data_obj || !data_obj || !data_obj.obj.menu_name){
			throw {'code':global.consts.Error.ERROR_PARAM,
				'message':global.consts.Message.ERROR_PARAM};
		}
		
		let params=super._addUserParams();
		params = super._addParams(['menu_name=',data_obj.obj.menu_name],params);
		let one = await inst.queryOne(null,params,null,'sort desc');
		if(one){
			return one;
		}
		
		let obj = null;
		if(data_obj && data_obj.obj && data_obj.obj.menu_id){
			obj= data_obj.obj;
		}
		if(!obj){
			params=super._addUserParams();
			one = await inst.queryOne(['max(sort) sort'],params,null,null);
			
			let sort = 1;
			if(one && one.sort)sort = one.sort+1;
			obj= {};
			let menu_no =1;
			one = await inst.queryOne(['max(menu_no) menu_no'],params,null,null);
			if(one && one.menu_no)menu_no = one.menu_no+1;
			obj.menu_name=data_obj.obj.menu_name;
			obj.u_id= this.req_obj.u_id;
			obj.menu_no= menu_no;
			obj.sort = sort;
			obj.menu_number= 'xdsdg_menu_'+menu_no;
			obj.menu_online= 1;
			obj.ex_no=0;
			console.log('create menu ' + JSON.stringify(obj));
			
			
		}
		let result = await inst.create(obj);	
		return result;			
	}

}
module.exports = JQCategoryCreateService;

